package MessageHelper

import (
	awesomeTask "awesomeTask/commom"
	awesomeTask2 "awesomeTask/config"
	"awesomeTask/system/helper"
	"awesomeTask/system/log"
	"net"
)

func CreateInfo(event string, sendInfo map[string]interface{}) string {
	sendInfo["event"] = event
	return helper.JsonEncode(sendInfo)
}
func SendEvent(event string, data map[string]interface{}, conn net.Conn) bool {
	sendData := data
	sendData["event"] = event
	sendData["uniqueId"] = awesomeTask2.GetConfigByKey("uniqueId")
	sendData["clientToken"] = awesomeTask2.GetConfigByKey("clientToken")
	sendDataString := CreateInfo(event, sendData)
	_, err := conn.Write(awesomeTask.PacketData([]byte(sendDataString)))
	if err != nil {
		log.GetLogger().Error(err.Error())
		return false
	}
	if err != nil {
		log.GetLogger().Error(err.Error())
		return false
	}
	return true
}
